<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<div class="searchArea">
				<form id="searchBar">
					<div class="fieldset1 clearFix">
						<div class="FXBR">
							<div class="fieldBox">
								<div class="label">付款类型</div>
								<div class="field">
									<select id="payType" name="payType" >
										<option value=" " selected="selected">请选择</option>
										<c:forEach items="${payTypeList}" var="item">
											<option value="${item.key}">${item.value}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">付款状态</div>
								<div class="field">
									<select id="payState" name="payState" >
										<option value=" " selected="selected">请选择</option>
										<c:forEach items="${payStateList}" var="item">
											<option value="${item.key}">${item.value}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">付款时间</div>
								<div class="field"><!-- ${sysDate} -->
									<input  type="text" id="actPayTmBegin" name="actPayTmBegin" class="ui-datepicker" value="">-
									<input  type="text" id="actPayTmEnd" name="actPayTmEnd" class="ui-datepicker" value="">
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">流程编号</div>
								<div class="field">
									<input type="text"  name="pNo" class="ui-textbox">
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">发起人</div>
								<div class="field">
									<input type="text" name="flowUser" class="ui-textbox">
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">费用种类</div>
								<div class="field">
									<input type="text" name="feeType" class="ui-textbox">
								</div>
							</div>
							<div class="fieldBox">
								<div class="label">付款公司主体</div>
								<div class="field">
									<select id="payerMain" name="payerMain" >
										<option value=" " selected="selected">请选择</option>
										<c:forEach items="${payerMainList}" var="item">
											<option value="${item.value}">${item.value}</option>
										</c:forEach>
									</select>
								</div>
							</div>
						</div>
						<div class="clearFix"></div>

						<div class="btnsBox formBtns notRight">
							<span id="searchBtn" class="sq-button-round">查询</span> 
							<span id="clearBtn" class="sq-button-round">清空</span> 
							<span class="sq-button-round" onclick="toSave('','add');">新建付款单</span> 
							
							<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide" />
						</div>

					</div>
				</form>
			</div>
			<!-- 列表显示块 -->
			<div id="ligergrid1" class="sq-grid"></div>

		</div>
	</div>



	<script type="text/javascript">
	var grid = null;
	var updateId = null;
	$(function () {
		$("#searchBar").ligerForm();
	    initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
	    searchBtnEvent();//查询按钮事件
	    clearBtnEvent();//清空按钮事件
	});
	
	 
	//新增修改集团公司保存 
	 $("#save").click(function(event) {
	        var form = liger.get("addForm");
	         if (!form.valid()) {
	        	$.ligerDialog.SQalert({content:LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
	            return false; 
	        } 
	        var data = form.getData();
	         if(data) {
		        data["id"] =updateId;
	        }
	         console.log(data);
	         /*return;  */
	        $.ligerDialog.hide();
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:data,
				url: '<%=path%>/rfbase/fncCapPayeeInfoBigAccount/save.do',
				beforeSend:function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
	    });
	
	
	 
	
	//查询参数
	function getSearchParams(){
		var form = new liger.get("searchBar");
		var data = form.getData();
		return data;
	}
	
	//初始化列表
	function initGrid(){
		$("#ligergrid1").ligerGrid({
			url:'<%=path%>/rfbase/fncCapPayeeInfoBig/initList.do',
			method:'get',
			parms:getSearchParams(),
			columns:[
				{ display: '付款类型', name: 'payTypeNm'},
				{ display: '费用种类', name: 'feeType'},
				{ display: '流程编号', name: 'pNo',
					render: function (rowdata, rowindex, value, column) { 
	        			if(StringUtils.isEmpty(value)){
	            			value = "";
	            		}
	        			var h = '';
	        		    h='<a href="javascript:showFlow(';
	                    h+="'"+rowdata.pInstId+"',";
	                    h+="'"+rowdata.audStsCd+"',";
	                    h+="'"+rowdata.id+"',";
	                    h+="'"+rowdata.busTyp+"'";
	                    h+=')">'+value+'</a>'
	                    return h;
        			}
            	},
				{ display: '发起人', name: 'flowUser'},
				{ display: '付款时间', name: 'actPayTm', render:renderDate},
				{ display: '付款金额', name: 'actPayAmt',
					render:function (rowdata, rowindex, value){
						var h="";
						if(rowdata.payState==1) {//已付状态，显示实际付款金额
							h = rowdata.actPayAmt;
						}else {//其他状态显示应付金额
							h = rowdata.payAmt;
						}
						return h;
					}
				},
				{ display: '付款账号', name: 'payerAccNo'},
				{ display: '付款状态', name: 'payStateNm'},
				{ display: '付款公司主体', name: 'payerMain'},
				{
					display:'操作',
					width:220,
					render:function (rowdata, rowindex, value){
						var h="";
						
		                h+='<a class="sq-button-hasicon" href="javascript:toSave(';
		            	h+="'"+rowdata.id+"','view'";
		                h+=")\"><i class='sqBtnIco_4'></i>详情</a>";
		                if(rowdata.payState=="2"){
		                	h+='<a class="sq-button-hasicon" href="javascript:startFlow(';
			            	h+="'"+rowdata.id+"','view'";
			                h+=")\"><i class='sqBtnIco_4'></i>发起流程</a>";
			                
			                h+='<a class="sq-button-hasicon" href="javascript:removeById(';
			            	h+="'"+rowdata.id+"'";
			                h+=")\"><i class='sqBtnIco_4'></i>删除</a>";
		                }
						return h;
					}
				},
			],
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton:false,
			width:'100%',
			height:'100%',
			heightDiff:-2,
			isScroll: true,
			checkbox:true,//列表是否有选择框
			rownumbers:true,//列表是否有行号
			
		});
		grid = liger.get("ligergrid1");
		grid.setHeight(100);
	}
	
	
	
	function toSave(id,operate){
		var title = "付款单详情";
		if(operate == "update") {
			title = "付款单修改";
		}else if(operate == "add") {
			title = "付款单新增";
		}
		var timestamp = new Date().getTime();
		var param = '<%=path%>/rfbase/fncCapPayeeInfoBig/toSave.do?id=' + id+'&operate='+operate;
		Add_navTab('fncCapPayeeInfoBig'+timestamp,title,param, function () {
			grid.reload();
		});
	}
	
	
	

		//清空按钮事件
		function clearBtnEvent() {
			$("#clearBtn").click(function(event) {
				$("#resetBtn").click(); //重置 input-text
				var form = liger.get("searchBar");
				 form.setData({  //重置select等特殊表单
					"payType":" ",
					"payState":" ",
					"payerMain":" ",
				}); 
				//liger.get('cstMgrOrgCd').clear();
				//searchOrgTree.clear();
			});
		}

		//查询按钮事件
		function searchBtnEvent() {
			$("#searchBtn").click(function(event) {
				var form = new liger.get("searchBar");
				var data = form.getData();
				//alert(JSON.stringify(data));
				for (name in data) {
					grid.setParm(name, $.trim(data[name]));
				}
				grid.reload();
			});
		}
		//格式化时间
		function renderDate(rowdata, index, value){
			var dateStr = "";
			if(null != value){
				var date = new Date(value);
				dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
			}
			return dateStr;
		}
		
		 function showFlow(_pInstId,_audStsCd,_dataId,busTyp){
		    	
		    	if(StringUtils.isEmpty(_pInstId)){
					UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
					return;
				}
		    	
		    	var _formUrl ="/rfbase/fncCapPayeeInfoBig/toSave.do?operate=view";
		    	var busTyp;
		    	 if(busTyp == "R021") {
		    		flowType="@@flowType=xx";
		    	}else {
		    		flowType="@@flowType=xx";
		    	}
		    	_formUrl = _formUrl + flowType+"@@id="; 
		    		
		    		
				var params = "?pInsId="+_pInstId+"&status="+_audStsCd+"&businessKey="+_dataId+"&formUrl="+_formUrl;
				Add_navTab('fncCapPayeeInfoBig_flow'+_pInstId,'查看流程',"<%=path%>/flow/flow/toFlowShowPageFowBus.do"+params);
		    }
		function startFlow(id){
			$.ligerDialog.confirm("是否确认发起流程?", function (flag) {
				if(!flag) return;
				var wait_dialog = null;
				$.ajax({
					type: 'post',
					dataType: 'json',
					
					url: '<%=path%>/rfbase/fncCapPayeeInfoBig/startFlow.do?id='+id+'&operate=0',
					beforeSend: function(){
						wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting"});
					},success:function(msg){
						wait_dialog.close();
						if(msg.success == 1){
								$.ligerDialog.SQalert({content: msg.info,SQ_type: "success",SQ_showButtons: true});
								grid.reload();
						}else{
							$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
						}
					},error:function (XMLHttpRequest, textStatus, errorThrown) { 
						wait_dialog.close();
						$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
					} 
				});
			});
			
		}
		
		function removeById(id){
			$.ligerDialog.confirm("是否确认删除吗?", function (flag) {
				if(!flag) return;
				var wait_dialog = null;
				$.ajax({
					type: 'get',
					dataType: 'json',
					url: '<%=path%>/rfbase/fncCapPayeeInfoBig/removeById.do?id='+id,
					beforeSend: function(){
						wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting"});
					},success:function(msg){
						wait_dialog.close();
						if(msg.success == 1){
								$.ligerDialog.SQalert({content: msg.info,SQ_type: "success",SQ_showButtons: true});
								grid.reload();
						}else{
							$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
						}
					},error:function (XMLHttpRequest, textStatus, errorThrown) { 
						wait_dialog.close();
						$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
					} 
				});
			});
			
		}
		
	</script>
</body>
</html>